package com.yz.newspaper.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yz.newspaper.pojo.po.Hits;
import com.yz.newspaper.pojo.po.PublishColumn;
import com.yz.newspaper.pojo.result.Result;
import com.yz.newspaper.service.IPublishColumnService;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 刊发栏目
 *
 * @author author
 * @since 2024-04-21
 */
@RestController
@RequestMapping("/publish-column")
public class PublishColumnController {

    @Autowired
    private IPublishColumnService publishColumnService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/all")
    public Result<List<PublishColumn>> getAll() {
        List<PublishColumn> list = publishColumnService.list();
        return Result.success(list);
    }

    /**
     * 根据媒体查询刊发栏目
     * @param media
     * @return
     */
    @GetMapping("/byMedia")
    public Result<List<PublishColumn>> getPublishByMedia(@NotNull String media) {
        if (media == null) {
            return  Result.error("请输入媒体");
        }
        List<PublishColumn> list = publishColumnService.list(new LambdaQueryWrapper<PublishColumn>()
                .eq(PublishColumn::getMedia, media));
        if (list.isEmpty()) {
            return Result.error("当前媒体没有刊发栏目");
        }
        return Result.success(list);
    }
}
